
load('summary_data/figA7.rda')

source('utils.R')

out = rbindlist(list(d12,d20,r12,r20)) %>%
  mutate(class = factor(class, levels = unique(class)[c(3:4,1:2)])) %>%
  mutate(lty = if_else(str_starts(class, 'R'), 'solid','dashed'),
         a= if_else(str_starts(class, 'R'), 1, 1)) %>%
  ggplot(aes(x = nat_quant, y = sq, fill = class, group = class, color = class, linetype = lty, alpha = a)) +
  geom_point(aes(alpha=a)) +
  geom_line() +
  theme_light() +
  scale_x_discrete(labels = x_l) +
  scale_linetype_identity() +
  scale_alpha_identity() +
  scale_color_manual(values = c("deepskyblue", "darkslateblue", "brown1", "darkred")[c(3:4, 1:2)]) +
  scale_y_continuous(
    labels = scales::label_percent(),
    limits = c(0, .55),
    breaks = c(.1, .2, .3, .4, .5)
  ) +
  labs(x = element_blank(), y = '% Donor Retention', fill = element_blank()) +
  guides(
    alpha = 'none',
    fill = 'none',
    color = guide_legend(
      nrow = 2,
      byrow = TRUE,
      title = element_blank()
    )
  ) +
  theme(
    legend.position = c(.7, .125),
    axis.text.x = element_text(
      angle = 25,
      vjust = .85,
      hjust = 0.5,
      size = 7
    ),
    legend.text = element_text(size = 7),
    strip.background = element_rect(fill = 'white'),
    strip.text.x = element_text(
      face = 'bold',
      size = 10,
      color = 'black'
    ),
    legend.spacing.y = unit(0, 'cm'),
    text = element_text(face = 'bold')
  )

ggsave(filename = 'figures/figA7.pdf', plot = out, width = 6, height = 4, units = 'in')
